<?php

use Illuminate\Http\Request;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

//['only' => ['index', 'create', 'store', 'edit', 'update', 'destroy']]

app('Dingo\Api\Routing\Router')->version(env('API_VERSION', 'v1'), function ($api) {
    $api->group(['namespace' => 'App\Http\Controllers\Admin', 'middleware' => ['auth.api']], function ($api) {

        /**
         * 非token认证
         */
        $api->post('login', 'AuthController@login')->name('login');

        /**
         * 需要token认证
         */
        $api->group([
            'middleware' => [
                'auth.user', // token校验中间件
            ],
        ], function ($api) {
            $api->get('profile', 'AuthController@profile')->name('profile');        // 登录信息
            $api->post('password', 'AuthController@changePwd');                     // 修改密码
            $api->post('logout', 'AuthController@logout')->name('logout');          // 登出

            /**
             * 分类
             */
            $api->resource('categories', 'CategoryController');

            /**
             * 文章
             */
            $api->resource('pages', 'PageController');

        });
    });
});